package com.sky.sky_server.controller.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sky.sky_common.result.Result;
import com.sky.sky_pojo.dto.DishItemVO;
import com.sky.sky_server.service.impl.SetmealServiceImpl;

import lombok.extern.slf4j.Slf4j;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealServiceImpl setmealServiceImpl;

    /**
     * 根据分类id查询套餐列表
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @Cacheable(value = "setmealCache", key = "#categoryId") //将查询结果缓存到setmealCache中, 拼接结果为setmealCache::categoryId
    public Result list(@RequestParam Long categoryId) {
        log.info("根据分类id查询套餐列表，categoryId={}", categoryId);
        return Result.success(setmealServiceImpl.selectByCategoryId(categoryId));
    }
    /**
     * 根据套餐id查询包含的菜品
     */
    @GetMapping("/dish/{id}")
    public Result dish(@PathVariable Long id) {
        log.info("根据套餐id查询包含的菜品，id={}", id);
        List<DishItemVO> dishItemVOS = setmealServiceImpl.selectDishBySetmealId(id);
        if(dishItemVOS == null)
            return Result.error("查询失败");
        return Result.success(setmealServiceImpl.selectDishBySetmealId(id));
    }
}
